home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Examples / Embed / Sources / EmbedCmd.cpp next >
Encoding:
Text File  |  1995-11-08  |  9.7 KB  |  326 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                EmbedCmd.cpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Author:                John Wendt
  7. //
  8. //    Copyright:    © 1993, 1995 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #include "Embed.hpp"
  13.  
  14. #ifndef EMBEDCMD_H
  15. #include "EmbedCmd.h"
  16. #endif
  17.  
  18. #ifndef EMBEDSEL_H
  19. #include "EmbedSel.h"
  20. #endif
  21.  
  22. #ifndef EMBEDPXY_H
  23. #include "EmbedPxy.h"
  24. #endif
  25.  
  26. #ifndef EMBEDPAR_H
  27. #include "EmbedPar.h"
  28. #endif
  29.  
  30. #ifndef EMBEDFRA_H
  31. #include "EmbedFra.h"
  32. #endif
  33.  
  34. // ----- Framework Includes -----
  35.  
  36. #ifndef FWPRESEN_H
  37. #include "FWPresen.h"
  38. #endif
  39.  
  40. // ----- OS Includes -----
  41.  
  42. #ifndef FWORDCOL_H
  43. #include "FWOrdCol.h"
  44. #endif
  45.  
  46. // ----- OpenDoc Includes -----
  47.  
  48. #ifndef SOM_Module_OpenDoc_Commands_defined
  49. #include <CmdDefs.xh>
  50. #endif
  51.  
  52. //========================================================================================
  53. // RunTime Info
  54. //========================================================================================
  55.  
  56. #ifdef FW_BUILD_MAC
  57. #pragma segment opfEmbed
  58. #endif
  59.  
  60. //========================================================================================
  61. // CEmbedEditCommand
  62. //========================================================================================
  63.  
  64. //----------------------------------------------------------------------------------------
  65. //    CEmbedEditCommand constructor
  66. //----------------------------------------------------------------------------------------
  67.  
  68. CEmbedEditCommand::CEmbedEditCommand(Environment *ev, 
  69.                                      ODCommandID commandID,
  70.                                      CEmbedPart* part, 
  71.                                      FW_CFrame* frame, 
  72.                                      FW_CSelection* selection,
  73.                                      FW_Boolean canUndo) :
  74.     FW_CEditCommand(ev, commandID, frame, canUndo),
  75.         fEmbedPart(part),
  76.         fPastedProxy(NULL),
  77.         fOldProxy(NULL)
  78. {
  79. }
  80.  
  81. //----------------------------------------------------------------------------------------
  82. //    CEmbedEditCommand destructor
  83. //----------------------------------------------------------------------------------------
  84.  
  85. CEmbedEditCommand::~CEmbedEditCommand()
  86. {
  87. }
  88.  
  89. //----------------------------------------------------------------------------------------
  90. //    CEmbedEditCommand::SaveUndoState
  91. //----------------------------------------------------------------------------------------
  92. void CEmbedEditCommand::SaveUndoState(Environment* ev)    // Override
  93. {
  94.     if ((fCommandID == kODCommandCut) || (fCommandID == kODCommandClear))
  95.         fPastedProxy = fEmbedPart->GetProxy(ev);
  96.     else if (fCommandID == kODCommandPaste)
  97.         fOldProxy = fEmbedPart->GetProxy(ev);
  98.  
  99. }
  100.  
  101. //----------------------------------------------------------------------------------------
  102. //    CEmbedEditCommand::FreeUndoState
  103. //----------------------------------------------------------------------------------------
  104. void CEmbedEditCommand::FreeUndoState(Environment* ev)    // Override
  105. {
  106.     if ((fCommandID == kODCommandCut) || (fCommandID == kODCommandClear))
  107.     {
  108.         delete fPastedProxy;
  109.     }
  110.     else if (fCommandID == kODCommandPaste)
  111.     {
  112.         // Delete the original proxy
  113.         delete fOldProxy;
  114.     }
  115. }
  116.  
  117. //----------------------------------------------------------------------------------------
  118. //    CEmbedEditCommand::SaveRedoState
  119. //----------------------------------------------------------------------------------------
  120. void CEmbedEditCommand::SaveRedoState(Environment *ev)    // Override
  121. {
  122.     if (fCommandID == kODCommandPaste) 
  123.         fPastedProxy = fEmbedPart->GetProxy(ev);
  124. }
  125.  
  126. //----------------------------------------------------------------------------------------
  127. //    CEmbedEditCommand::FreeRedoState
  128. //----------------------------------------------------------------------------------------
  129. void CEmbedEditCommand::FreeRedoState(Environment* ev)    // Override
  130. {
  131.     if (fCommandID == kODCommandPaste)
  132.     {
  133.         // Delete the pasted proxy
  134.         delete fPastedProxy;
  135.     }
  136. }
  137.  
  138. //----------------------------------------------------------------------------------------
  139. //    CEmbedEditCommand::UndoIt
  140. //----------------------------------------------------------------------------------------
  141. void CEmbedEditCommand::UndoIt(Environment *ev)    // Override
  142. {
  143.     switch (fCommandID)
  144.     {
  145.         case kODCommandCut:
  146.         case kODCommandClear:
  147.             this->RestorePart(ev);
  148.             break;
  149.  
  150.         case kODCommandPaste:
  151.             this->RemovePart(ev);
  152.             this->RestoreOldPart(ev);
  153.             break;
  154.     }    
  155. }
  156.  
  157. //----------------------------------------------------------------------------------------
  158. //    CEmbedEditCommand::RedoIt
  159. //----------------------------------------------------------------------------------------
  160. void CEmbedEditCommand::RedoIt(Environment *ev)    // Override
  161. {
  162.     switch (fCommandID)
  163.     {
  164.         case kODCommandCut:
  165.         case kODCommandClear:
  166.             this->RemovePart(ev);
  167.             break;
  168.  
  169.         case kODCommandPaste:
  170.             this->RemovePart(ev);
  171.             this->RestorePart(ev);
  172.             break;
  173.     }    
  174. }
  175.  
  176. //----------------------------------------------------------------------------------------
  177. //    CEmbedEditCommand::RestorePart
  178. //----------------------------------------------------------------------------------------
  179. void CEmbedEditCommand::RestorePart(Environment *ev)    // Override
  180. {
  181.     CEmbedSelection* selection = (CEmbedSelection*)fSelection;
  182.     
  183.     fEmbedPart->SetProxy(ev, fPastedProxy);
  184.     fPastedProxy->AttachEmbeddedFrames(ev);
  185.         
  186.     fFrame->GetPresentation(ev)->Invalidate(ev);
  187. }
  188.  
  189. //----------------------------------------------------------------------------------------
  190. //    CEmbedEditCommand::RemovePart
  191. //----------------------------------------------------------------------------------------
  192. void CEmbedEditCommand::RemovePart(Environment *ev)    // Override
  193. {
  194.     // Clear the selection, which includes detaching the proxy frames.
  195.     fSelection->ClearSelection(ev);
  196. }
  197.  
  198. //----------------------------------------------------------------------------------------
  199. //    CEmbedEditCommand::RestoreOldPart
  200. //----------------------------------------------------------------------------------------
  201. void CEmbedEditCommand::RestoreOldPart(Environment* ev)
  202. {
  203.     // restore the previous part, if any
  204.     if (fOldProxy)
  205.     {
  206.         fEmbedPart->SetProxy(ev, fOldProxy);
  207.         if (fOldProxy)
  208.             fOldProxy->AttachEmbeddedFrames(ev);
  209.  
  210.         // Force a redraw
  211.         fFrame->GetPresentation(ev)->Invalidate(ev);
  212.     }
  213. }
  214.  
  215. //========================================================================================
  216. //    class CProxyDropCommand
  217. //========================================================================================
  218.  
  219. //----------------------------------------------------------------------------------------
  220. //    CProxyDropCommand constructor
  221. //----------------------------------------------------------------------------------------
  222.  
  223. CProxyDropCommand::CProxyDropCommand(Environment* ev,
  224.                                      CEmbedPart* itsPart,
  225.                                      FW_CFrame* frame,
  226.                                      ODDragItemIterator* dropInfo, 
  227.                                      ODFacet* odFacet,
  228.                                      const FW_CPoint& dropPoint) : 
  229.     FW_CDropCommand(ev, (FW_CPart*)itsPart, frame, dropInfo, odFacet, dropPoint, FW_kCanUndo),
  230.     fEmbedPart(itsPart),
  231.     fDroppedProxy(NULL),
  232.     fOldProxy(NULL)
  233. {
  234.     fEmbedSelection = (CEmbedSelection*) frame->GetPresentation(ev)->GetSelection(ev);
  235.     this->SetMenuStrings(ev, "Undo Drop", "Redo Drop");
  236.  
  237.     FW_END_CONSTRUCTOR
  238. }
  239.  
  240. //----------------------------------------------------------------------------------------
  241. //    CProxyDropCommand destructor
  242. //----------------------------------------------------------------------------------------
  243.  
  244. CProxyDropCommand::~CProxyDropCommand()
  245. {
  246. }
  247.  
  248. //---------------------------------------------------------------------------------------
  249. //    CProxyDropCommand::UndoIt
  250. //---------------------------------------------------------------------------------------
  251. void CProxyDropCommand::UndoIt(Environment* ev)
  252. {
  253.     FW_ASSERT(fDroppedProxy);
  254.  
  255.     // remove the dropped part
  256.     fEmbedSelection->ClearSelection(ev);
  257.  
  258.     // restore the previous part, if any
  259.     fEmbedPart->SetProxy(ev, fOldProxy);
  260.     if (fOldProxy)
  261.         fOldProxy->AttachEmbeddedFrames(ev);
  262.  
  263.     // Force a redraw
  264.     fFrame->GetPresentation(ev)->Invalidate(ev);
  265. }
  266.  
  267. //---------------------------------------------------------------------------------------
  268. //    CProxyDropCommand::RedoIt
  269. //---------------------------------------------------------------------------------------
  270. void CProxyDropCommand::RedoIt(Environment* ev)
  271. {
  272.     FW_ASSERT(fDroppedProxy);
  273.  
  274.     // remove the original embedded part
  275.     fEmbedSelection->ClearSelection(ev);
  276.  
  277.     // restore the dropped part
  278.     fEmbedPart->SetProxy(ev, fDroppedProxy);
  279.     fDroppedProxy->AttachEmbeddedFrames(ev);
  280.  
  281.     // Force a redraw
  282.     fFrame->GetPresentation(ev)->Invalidate(ev);
  283. }
  284.  
  285. //----------------------------------------------------------------------------------------
  286. //    CProxyDropCommand::SaveUndoState
  287. //----------------------------------------------------------------------------------------
  288. void CProxyDropCommand::SaveUndoState(Environment *ev)
  289. {
  290.     // Save the proxy for the part that's currently embedded
  291.     fOldProxy = fEmbedPart->GetProxy(ev);
  292. }
  293.  
  294. //---------------------------------------------------------------------------------------
  295. //    CProxyDropCommand::SaveRedoState
  296. //---------------------------------------------------------------------------------------
  297. void CProxyDropCommand::SaveRedoState(Environment *ev)
  298. {
  299.     // Save the proxy for the part that was just dropped
  300.     fDroppedProxy = fEmbedPart->GetProxy(ev);
  301. }
  302.  
  303. //---------------------------------------------------------------------------------------
  304. //    CProxyDropCommand::CommitDone
  305. //---------------------------------------------------------------------------------------
  306. void CProxyDropCommand::CommitDone(Environment* ev)
  307. {
  308.     if (fOldProxy)
  309.     {
  310.         // Delete the original proxy
  311.         delete fOldProxy;
  312.         fOldProxy = NULL;
  313.     }
  314. }
  315.  
  316. //---------------------------------------------------------------------------------------
  317. //    CProxyDropCommand::CommitUndone
  318. //---------------------------------------------------------------------------------------
  319. void CProxyDropCommand::CommitUndone(Environment* ev)
  320. {
  321.     // Delete the dropped proxy
  322.     delete fDroppedProxy;
  323. }
  324.  
  325.  
  326.